package com.tjp.eight.ui.fragment.mymsg.receicezan;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tjp.eight.R;
import com.tjp.eight.utils.ActivityUtils;
import com.tjp.eight.utils.AppUtils;
import com.tjp.eight.views.CircleImageView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/2/27.
 */
public class ReceiveZanAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context context;
    private ArrayList<ZanRModel.ZanItem> models;

    public ReceiveZanAdapter(Context context) {
        this.context = context;
        models = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_my_msg_sub, parent, false);
        return new ReceiveZanViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
        final String coid = models.get(position).coid;
        ((ReceiveZanViewHolder) holder).tv_msg_who_tips.setText("赞了您的评论");
        ((ReceiveZanViewHolder) holder).tv_msg_who.setText("" + models.get(position).name);
        ((ReceiveZanViewHolder) holder).tv_pass_time.setText("" + models.get(position).pass_time);
        Glide.with(context).load(models.get(position).iconurl).error(R.drawable.icon_login).into(((ReceiveZanViewHolder) holder).civ_msg_user);
        if (models.get(position).if_view == 1) {
            AppUtils.setTextViewColor(((ReceiveZanViewHolder) holder).tv_msg_who_tips, "#999999");
            AppUtils.setTextViewColor(((ReceiveZanViewHolder) holder).tv_msg_who, "#999999");
        } else {
            AppUtils.setTextViewColor(((ReceiveZanViewHolder) holder).tv_msg_who_tips, "#000000");
            AppUtils.setTextViewColor(((ReceiveZanViewHolder) holder).tv_msg_who, "#000000");
        }
        ((ReceiveZanViewHolder) holder).view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppUtils.setTextViewColor(((ReceiveZanViewHolder) holder).tv_msg_who_tips, "#999999");
                AppUtils.setTextViewColor(((ReceiveZanViewHolder) holder).tv_msg_who, "#999999");
                ActivityUtils.startCommentDetails(context, coid, "");
            }
        });
    }

    public void addData(ArrayList<ZanRModel.ZanItem> data) {
        if (data == null || data.isEmpty()) return;
        int index = models.size();
        for (ZanRModel.ZanItem item : data) {
            models.add(item);
        }
        notifyItemRangeInserted(index, models.size());
    }


    class ReceiveZanViewHolder extends RecyclerView.ViewHolder {
        TextView tv_msg_who_tips;
        TextView tv_msg_who;
        TextView tv_pass_time;
        CircleImageView civ_msg_user;
        View view;

        public ReceiveZanViewHolder(View itemView) {
            super(itemView);
            view = itemView;
            tv_msg_who_tips = (TextView) itemView.findViewById(R.id.tv_msg_who_tips);
            tv_msg_who = (TextView) itemView.findViewById(R.id.tv_msg_who);
            tv_pass_time = (TextView) itemView.findViewById(R.id.tv_pass_time);
            civ_msg_user = (CircleImageView) itemView.findViewById(R.id.civ_msg_user);
        }
    }

    @Override
    public int getItemCount() {
        return models.size();
    }
}
